package cn.ffcs.unm.education.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.education.dao.EducationDao;
import cn.ffcs.unm.education.model.Education;
import cn.ffcs.unm.education.model.EducationTraining;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("educationDao")
public class EducationDaoImpl extends BaseDaoImpl implements EducationDao {

	@Override
	public PageInfo queryPageInfoByEducation(Education education,
			int currentPage, int pageSize) {

		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT * FROM VIEW_HI_PSNDOC_EDU where 1 = 1 ");

		List<Object> params = new ArrayList<Object>();
		if (null != education) {
			if (!StrUtil.isEmpty(education.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(education.getMonthId());
			}
			if (!StrUtil.isEmpty(education.getStaffName())) {
				sb.append(" AND staffName LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(education.getStaffName())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, Education.class);
	}

	@Override
	public PageInfo queryPageInfoByEducationTraining(
			EducationTraining educationTraining, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" SELECT * FROM VIEW_HI_PSNDOC_TRAIN WHERE 1 = 1 ");
		List<Object> params = new ArrayList<Object>();
		if (null != educationTraining) {
			if (!StrUtil.isEmpty(educationTraining.getMonthId())) {
				sb.append(" AND monthId = ? ");
				params.add(educationTraining.getMonthId());
			}
			if (!StrUtil.isEmpty(educationTraining.getName())) {
				sb.append(" AND name LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(educationTraining
								.getName()) + "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, EducationTraining.class);
	}

}
